A14 - Four Boxes
提出
TLE
code: python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# O(pow(1000, 4))
ab = []
cd = []
for va in a:
for vb in b:
ab.append(va + vb)
for vc in c:
for vd in d:
cd.append(vc + vd)
for vab in ab:
for vcd in cd:
if vab + vcd == k:
print("Yes")
exit()
print("No")
解答
code: python
import bisect
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# O(pow(1000, 4))
ab = []
cd = []
for va in a:
for vb in b:
ab.append(va + vb)
for vc in c:
for vd in d:
cd.append(vc + vd)
cd.sort()
for i in range(len(ab)):
p = bisect.bisect_left(cd, k-abi) if p < n*n and cdp == k-abi: print("Yes")
exit(0)
print("No")